<?php
/**
 * Created by PhpStorm.
 * User: zxy
 * Date: 2018/3/3
 * Time: 22:08
 */
date_default_timezone_set("PRC");
define("URL","http://www.maxun.xyz/controller/ScanController.php?n=");
require_once  __DIR__."/../libs/phpqrcode.php";
class PrintCodeController
{
    function Run($count){
        $num=0;
        for ($i=0;$i<$count;$i++){
            $num++;
            $id = uniqid();
            $this->scerweima(URL.$id,$id);
        }
        echo "生成了".$num."张二维码,请到根目录print文件夹查看！";
    }
    function scerweima($url='',$id){
        $value = $url;                  //二维码内容
        $errorCorrectionLevel = 'L';    //容错级别
        $matrixPointSize = 5;           //生成图片大小

        //生成二维码图片
        $dir = iconv("UTF-8", "GBK", "../print/".date("Y-m-d/",time()));
        if (!file_exists($dir)){
            mkdir ($dir,0777,true);
        }
        $filename = '../print/'.date("Y-m-d/",time()).$id.'.png';
        QRcode::png($value,$filename , $errorCorrectionLevel, $matrixPointSize, 2);

        $QR = $filename;                //已经生成的原始二维码图片文件


        $QR = imagecreatefromstring(file_get_contents($QR));
        //输出图片
        imagepng($QR, '../view/img/qrcode.png');
        imagedestroy($QR);
        return '<img src="../view/img/qrcode.png" alt="扫一扫">';
    }
}
$a  = new PrintCodeController();
$a->Run($_GET["n"]);